﻿using FrameDesign.Example1.Scripts;
using FrameDesign.Example1.Scripts.Command;
using FrameDesign.FrameWork;
using FrameDesign.FrameWork.Rule;
using FrameWorkDesign.Example.Event;
using Model;
using UnityEngine;

namespace FrameWorkDesign.Example.Game
{
    public class Game : MonoBehaviour,IController
    {
        void Start()
        {
            this.RegisterEvent<GameStartEvent>(OnGameStart);

            this.RegisterEvent<OnCountDownEndEvent>(e => { transform.Find("Enemies").gameObject.SetActive(false); })
                .UnRegisterWhenGameObjectDestroyed(gameObject);

            this.RegisterEvent<GamePassEvent>(e => { transform.Find("Enemies").gameObject.SetActive(false); })
                .UnRegisterWhenGameObjectDestroyed(gameObject);
        }

        private void OnGameStart(GameStartEvent e)
        {
            var enemyRoot = transform.Find("Enemies");
            
            enemyRoot.gameObject.SetActive(true);

            foreach (Transform childTrans in enemyRoot)
            {
                childTrans.gameObject.SetActive(true);
            }
        }

        private void OnDestroy()
        {
            this.UnRegisterEvent<GameStartEvent>(OnGameStart);
        }

        public IArchitecture GetArchitecture()
        {
            return PointGame.Interface;
        }
    }
}